import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/controller/books.dart';
//import 'package:ichinesereader/pages/book/bookQuizForApp.dart';
//import 'package:ichinesereader/utils/helper.dart';
import 'package:ichinesereader/widgets/grids/bookGridWithCheckBox.dart';
import '../../constants.dart';
import '../../controller/user.dart';

///import '../../models/book/BookArguments.dart';

// ignore: must_be_immutable
class RecBookDialog extends StatelessWidget {
  String btitle;
  final String bcode;
  final String bid;
  final String? assignmentId;
  final NanhaiBookReadingTypes readingType;
  final String? userName;
  final bool quizAvailable;
  final bool readComplete;
  final box = Hive.box('appconfig');
  RecBookDialog(
      {Key? key,
      required this.btitle,
      required this.bcode,
      required this.bid,
      this.assignmentId,
      required this.readingType,
      this.userName,
      required this.quizAvailable,
      required this.readComplete
      //required this.books,
      })
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final BooksController _bookController = Get.find();
    final UserController _usersController = Get.find();
    //_bookController.fetchgRecommendedBookItems(bid);
    return Obx(() {
      return AlertDialog(
        // title: Text('this.title'),
        // titleTextStyle: TextStyle(
        //     fontWeight: FontWeight.bold,
        //     letterSpacing: 1,
        //     color: Get.isDarkMode ? Color(0xffcccccc) : Colors.black,
        //     fontSize: 20),
        // backgroundColor: Get.isDarkMode
        //     ? (Color(0xff333333))
        //     : Color.fromARGB(255, 234, 241, 238),
        // shape: RoundedRectangleBorder(
        //     borderRadius: BorderRadius.all(Radius.circular(20))),
        content: Container(
          height: 480,
          width: MediaQuery.of(context).size.width * 0.8,
          child: Column(
            //crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              // SizedBox(height: 15),
              // if (quizAvailable && readComplete)
              //   MaterialButton(
              //       color: Theme.of(context).colorScheme.secondary,
              //       onPressed: () {
              //         if ((GetPlatform.isDesktop || GetPlatform.isMacOS) &&
              //             !GetPlatform.isWeb) {
              //           launchInWebViewWithJavaScript(
              //               '${Constants.BaseURL}icr/student/quiz/$bid');
              //         } else if (GetPlatform.isWeb) {
              //           Navigator.pushNamed(context, '/student/quiz',
              //               arguments: BookArguments(
              //                 bid,
              //                 bcode,
              //                 btitle,
              //                 assignmentId,
              //                 readingType,
              //                 userName,
              //               ));
              //         } else {
              //           Navigator.of(context).pop();
              //           Get.to(() => InAppWebViewAppBookQuizScreen(
              //                 bookCode: bcode,
              //                 bookId: bid,
              //                 bookTitle: btitle,
              //                 assignmentId: assignmentId,
              //                 readingType: readingType,
              //               ));
              //         }
              //       },
              //       child: Text('Go to Quiz Page'.tr)),
              SizedBox(height: 10),
              Text(
                'There are ${_bookController.recommendedBookItems.length} recommended books',
                style: TextStyle(fontSize: 20),
              ),
              SizedBox(height: 10),
              Flexible(
                child: Center(
                  child: _bookController.obx(
                    (data) => BookGridWithCheckBox(
                      books: _bookController.recommendedBookItems,
                      readingType: NanhaiBookReadingTypes.leveled,
                    ),
                    onEmpty: Text('Books not available'.tr),
                    // onLoading: Center(
                    //     child: CircularProgressIndicator(
                    //   backgroundColor: Get.theme.primaryColorDark,
                    //   strokeWidth: 9.0,
                    // )),
                  ),
                ),
              ),
              MaterialButton(
                  color: Theme.of(context).colorScheme.secondary,
                  onPressed: () {
                    _usersController.refreshLevelPercentage();

                    Navigator.of(context).pop();
                  },
                  child: Text('Close'.tr))
            ],
          ),
        ),
      );
    });
  }
}
